<?php
	//ob_start();
	session_start();
	include('../config/config-inc.php');
	//include('../classes/class.db.php');
	include('../classes/class.user.php');
	//include('../classes/class.mail.php');

	if(isset($_GET['uname']) && isset($_GET['pswd']))
	{
		$user = new User($db);
		$user->setUserName($_GET['uname']);
		$user->setUserPassword($_GET['pswd']);
		$user->userLogin();
		//echo sizeof($_SESSION['user_details']);
		if(sizeof($_SESSION['user_details']) == 1)
		{
			echo 'O';
		}
		else
		{
			echo 'No';
		}
//		print_r($_SESSION['user_details']);
		unset($_SESSION['user_details']);
		
/*		$usr_name	= $_GET['uname'];
		$usr_pwd 	= md5($_GET['pswd']);
	
		$login_result = $db->select("users","User_ID='$usr_name' AND User_Password='$usr_pwd'");
		
		if(sizeof($login_result) < 1)
		{
			echo '0';
		}
		else
		{
			// to get the user access level details
			$user_access_result = $db->select("user_access_levels","Access_NO={$login_result[0]['User_Access_level']}");
	
			//update the login date-time in users table(using update prepare statement)
			$login_time 		= date('Y-m-d H:i:s');
			$login_time_update	= array("Last_Login_Date" => $login_time);
			$login_time_bind 	= array(":userid" => $login_result[0]['User_ID']);
			$db->update("users",$login_time_update,"User_ID = :userid",$login_time_bind);
			
			// Store the user details into session
			session_regenerate_id();
			$new_session_id = session_id();
			$_SESSION["user"]['sess_id']	 = $new_session_id;
			$_SESSION["user"]['id'] 		 = $login_result[0]['User_ID'];
			$_SESSION["user"]['fullname'] 	 = $login_result[0]['User_First_Name'].' '.$login_result[0]['User_Last_Name'];
			$_SESSION["user"]['email'] 		 = $login_result[0]['User_Email_ID'];
			$_SESSION["user"]['access_level']= $user_access_result[0]['Access_Levels'];
			$_SESSION["user"]['is_active']	 = $login_result[0]['Is_Active'];
			$_SESSION["user"]['last_login']	 = date('F j, Y   g:i A',strtotime($login_result[0]['Last_Login_Date']));

			//functionality to expire this session after 30 mins
			setcookie('sudeep_isLoggedIn', $new_session_id, time()+1800);			
			
			//send email about the login
			$loginMail = new sMail();
			$loginMail->addUser("sudeep@pinacle.co.in");
			$loginMail->setFrom("Admin <no-reply@sudeep.co.in>");
			$loginMail->setHTML();
			$loginMail->setPriority(3);
			$loginMail->setSubject("Visitor Information");
			//$login_details = "A test";
			$login_details = "<b>User: </b>$login_result[0]['User_ID']<br /><b>Time: </b>$login_time<br /><b>Referrer: </b>{$_SERVER['HTTP_REFERER']}";
			$loginMail->setContent($login_details);
			//$loginMail->send();
			echo $new_session_id;
			ob_end_flush();
		}*/
	}
	elseif(isset($_GET["act"]) && isset($_GET["id"]))
	{
		//execute the below code after validating GET and ID and that it s for logout.
		unset($_SESSION);
		session_destroy();
		setcookie('sudeep_isLoggedIn','', time() - 1800);		// Unset the cookie as well.
		header('location:login.php?do=logout');
	}
?>